package com.beiding.businessplatform.data;

import java.util.UUID;

public class BeConfig {
    private static BeCreator beMaker = new BeCreator() {
        @Override
        public <T extends Be> T make(Class<T> t) {
            try {
                T instance = t.newInstance();
                instance.setId(getIdMake().create());
                return instance;
            } catch (InstantiationException | IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }
    };

    public static BeCreator getBeMaker() {
        return beMaker;
    }

    public static void setBeMaker(BeCreator beMaker) {
        BeConfig.beMaker = beMaker;
    }

    private static IdMaker idMake = () -> UUID.randomUUID().toString();

    public static void setIdMake(IdMaker idMake) {
        BeConfig.idMake = idMake;
    }

    public static IdMaker getIdMake() {
        return idMake;
    }
}
